<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      v-show="showSearch"
      :inline="true"
    >
      <el-form-item label="申请人真实姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入申请人姓名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流程状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >查询</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!--代理商申请列表-->
    <el-table v-loading="loading" :data="applylist"> 
      <el-table-column label="序号" prop="id" />
      <el-table-column label="申请人真实姓名" prop="realName" />
      <el-table-column label="申请人电话" prop="userPhone"/>
      <el-table-column label="商户名称" prop="shopName" />
      <el-table-column label="申请时间" prop="applyTime" />
      <el-table-column label="通过时间" prop="passTime"/>
      <el-table-column label="申请理由" prop="applyReason" :show-overflow-tooltip="true"/>
      <el-table-column label="流程状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0" style="color: orange">待审核</span>
          <span v-if="scope.row.status == 1" style="color: green">通过</span>
          <span v-if="scope.row.status == 2" style="color: red">未通过</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status == 0"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:goods:edit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            v-if="scope.row.status == 2"
            @click="rejectReason(scope.row)"
            v-hasPermi="['system:goods:edit']"
          >查看理由</el-button>
          <span v-if="applylist.status == 1">已审核</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
     <!-- 审核申请详情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px">
        <el-form-item label="申请时间 :" prop="applyTime">
          <span>{{form.applyTime}}</span>
        </el-form-item>
        <el-form-item label="id :" prop="id">
          <span>{{form.id}}</span>
        </el-form-item>
        <el-form-item label="申请人姓名 :" prop="realName">
          <span>{{form.realName}}</span>
        </el-form-item>
        <el-form-item label="商户名称 :" prop="shopName">
          <span>{{form.shopName}}</span>
        </el-form-item>
        <el-form-item label="状态 :">
        <span v-if="form.status == 0">审核中 </span>
        <span v-if="form.status == 1">通过  </span>
        <span v-if="form.status == 2">未通过 </span>
        </el-form-item>
        <el-form-item label="申请人电话 :" prop="userPhone">
          <span>{{form.userPhone}}</span>
        </el-form-item>
        <el-form-item label="申请时间 :" prop="applyTime">
            <span>{{form.applyTime}}</span>
        </el-form-item>
        <el-form-item label="申请理由 :" prop="applyReason">
            <span>{{form.applyReason}}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" style="float: left">通  过</el-button>
        <el-button @click="cancel" >驳  回</el-button>
      </div>
    </el-dialog>
<!-- 驳回理由 -->
    <el-dialog title="驳回理由" :visible.sync="rejectopen" width="500px" append-to-body>
        <el-form ref="rejectForm" :model="rejectForm" label-width="100px">
          <el-form-item label="驳回理由 :" prop="reject">
           <span>{{rejectForm.reject}}</span>
          </el-form-item>
        </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { applyList, getapplyList, apply} from "@/api/apply/apply"
export default {
  data() {
    return {
      //驳回理由弹出层
      rejectopen: false,
      //驳回理由列表
      rejectForm:[],
      showbtn: true,
      //表单
      total: 0,
      // 表单参数
      form: {},
      //是否弹出层
      open: false,
      // 弹出层标题
      title: "",
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 抖音用户列表格数据
      applylist: [],
      // 状态数据字典
      statusOptions: [
        { dictLabel: "待审核", dictValue: "0" },
        { dictLabel: "通过", dictValue: "1" },
        { dictLabel: '未通过', dictValue: '2'}
      ],
      
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },    
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询抖音用户列表 */
    getList() {
      this.loading = true;
      applyList(this.queryParams).then((response) => {
        this.applylist = response.rows;
        this.applylist.forEach(item => {
           if(!item.passTime){
             item.passTime="未审核";
           }
          } 
        )
        this.total = response.total;
        this.loading = false;
      });
    },
    /**查看理由按钮 */
    rejectReason (row) {
       this.reset();
       const ids = row.id || this.ids;
       getapplyList(ids).then((response) => {
         this.rejectForm = response.data
         this.rejectopen = true;
       })
        
    },
    /** 审核按钮操作 */
    handleUpdate(row) {
      this.reset();
      const applyIds = row.id || this.ids;
      getapplyList(applyIds).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "审核";
      });
    },    
    /** 通过按钮 */
    submitForm: function () {
            const  applyIds = this.form.id;
            apply({applyId: applyIds, status: 1, context: '通过'}).then((response) => {
              this.msgSuccess('审核通过');
              this.getList();
              this.open = false;
              // this.showbtn = false;
            })
    }, 
    // 驳回按钮
    cancel() {
       const applyIds = this.form.id;
       const _this = this;
       this.$prompt('请输入的驳回理由', "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        inputPattern: /^.{5,50}$/,
        inputErrorMessage: "驳回内容不能小于5个字大于50个字",
      }).then(({ value }) => {
      apply({
          applyId: applyIds,
          status:2,
          context:value
      }).then((response) => {
        this.msgSuccess("驳回成功");
        this.open = false;
        // this.showbtn = false;
        this.getList();
      })
      }).catch(() => {});

    },
  },
};
</script>

<style>
</style>